package com.hdax.dm.controller;

import com.hdax.dm.exceptions.DmException;
import com.hdax.dm.service.loginService;
import com.hdax.dm.service.registerService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class SMSRegisterController {

    @Autowired
    private registerService registerService;

    @Autowired
    private loginService loginService;

    /**
     * 使用手机号注册
     */
    @PostMapping("register")
    public CommonResponse<Integer> register(@RequestBody Map<String,Object> params){
        CommonResponse<Integer> i = registerService.register(params);
        return i;
    }

    /**
     * 获取注册验证码
     */
    @PostMapping("code")
    public CommonResponse<String> code(@RequestBody Map<String,String> params){
        return loginService.msg(params);
    }

    //局部异常处理
    @ExceptionHandler(value = {DmException.class})
    public CommonResponse<String> exceptionHandler(DmException e){
        return ResponseUtil.returnFail(e);
    }
}
